﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace pxt
{
    public enum projectile_type { Spam, Cooldown, Death, Revive} 


    public class Projectile
    {
        // Members
        protected int mDamage;
        protected Vector2 mPosition, mVelocity;
        protected Rectangle mBoundingRect;
        protected float mSpeed;
        protected Texture2D mTexture;
        protected Player mOwner;
        protected projectile_type mType; // type of projectile
        protected bool mIsActive;

        // Functions
        public Projectile(projectile_type projType, Vector2 pos, Vector2 vel, Player owner)
        {
            mType = projType;
            mPosition = pos;
            mOwner = owner;
            mIsActive = true;

            // set the rect based on the type -- 
            mBoundingRect = new Rectangle((int)pos.X, (int)pos.Y, 8, 8);

            // set the damage based on type
            switch (projType)
            {
                case projectile_type.Spam:
                    {
                        mSpeed = 5.0f;
                        mDamage = 5;
                        break;
                    }
                case projectile_type.Cooldown:
                    {
                        // TODO : change bounding box
                        mSpeed = 5.0f;
                        mDamage = 15;
                        break;
                    }
                case projectile_type.Death:
                    {
                        mSpeed = 8.0f;
                        mDamage = 9999999;
                        break;
                    }
                default:
                    {
                        mSpeed = 0.0f;
                        mDamage = 0;
                        break;
                    }
            };

            mVelocity = vel * mSpeed;
        }

        public void Draw()
        {
            if(mType != projectile_type.Revive)
                GameSystems.Graphics.DrawImage(mTexture, mPosition, Color.White);
        }

        public void Update(GameTime gt)
        {
            // update our positions
            mBoundingRect.X = (int)mPosition.X;
            mBoundingRect.Y = (int)mPosition.Y;

            // check for a collision

            mPosition += mVelocity;
        }

        public void Kill()
        {
            mIsActive = false;
        }

        // Properties
        public Texture2D Texture
        {
            get { return mTexture; }
            set 
            { 
                mTexture = value;
                mBoundingRect.Width = mTexture.Width;
                mBoundingRect.Height = mTexture.Height;
            }
        }
        public Vector2 Position
        {
            get { return mPosition; }
            set 
            {
                if (value != null)
                {
                    mPosition = value;
                }
            }
        }
        public Player Owner
        {
            get { return mOwner; }
            set
            {
                if (value != null)
                {
                    mOwner = value;
                }
            }
        }

        public Rectangle Bounds
        {
            get { return mBoundingRect; }
        }

        public bool Active
        {
            get { return mIsActive; }
        }

        public int Damage
        {
            get { return mDamage; }
        }

        public projectile_type ProjectileType
        {
            get { return mType; }
            set { mType = value; }
        }
    }
}
